package zju.ccnt.rest.repository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import zju.ccnt.rest.domain.Resource;

/**
 * Created by zha on 14/11/12.
 */
@Repository
public interface ResourceRepository extends PagingAndSortingRepository<Resource, String> {

    public Resource findByHashValue(String hashValue);

    @Modifying
    @Transactional
    @Query(value = "update resource set has_uploaded = 1 where hash_value=:hashValue", nativeQuery = true)
    int uploadedResource(@Param("hashValue") String hashValue);
}
